//
//  ForgetPasswordViewController.swift
//  LongTermInsurance
//
//  Created by DYD on 2019/1/25.
//  Copyright © 2019 HeChao. All rights reserved.
//

import UIKit

class ForgetPasswordViewController: BaseViewController {

    @IBOutlet weak var idTF: UITextField!
    
    @IBOutlet weak var sheBaoTF: UITextField!
    
    @IBOutlet weak var nameTF: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        title = "密码重置"
        
//        idTF.delegate = self
//        sheBaoTF.delegate = self
//        //        sheBaoTF.keyboardType = .numberPad
//
//        nameTF.delegate = self
        
    }
    
    @IBAction func resetAction(_ sender: Any) {
        guard let idString = idTF.text, idString.count > 0 else {
            CDUtility.showMSG(message: idTF.placeholder ?? "")
            return
        }
        
        if !CDUtility.checkUserIdCard(idString) {
            CDUtility.showMSG(message: "请输入正确的身份证号码~")
            return
        }
        
        guard let sheBaoString = sheBaoTF.text, sheBaoString.count > 0 else {
            CDUtility.showMSG(message: sheBaoTF.placeholder ?? "")
            return
        }
        
        guard let nameString = nameTF.text, nameString.count > 0 else {
            CDUtility.showMSG(message: nameTF.placeholder ?? "")
            return
        }
        
        //        {"IDNum":"320522196901156190",
        //            "Name":"杨培良",
        //            "Password":"123456",
        //            "PerCardNum":"JSE000001079",
        //            "TelNum":"13771911349"}
        
        
        let values = ["IDNum": idString,
                      "Name": nameString,
                      "PerCardNum": sheBaoString,].convertToJsonString()
        let p0 = "<CodeName>"+"passwordrest"+"</CodeName>"
        let p1 = "<json>"+values+"</json>"
        
        let paramString = p0 + p1
        
        NetworkingHandle.oldfetchNetworkData(method: "ExeHNService", paramString: paramString, success: { (dict) in
            if let code = dict["Code"] as? Int,code == 0 {
//                UserDefaults.standard.set(idString, forKey: CDUserDefaultKey.loginID)
//                UserDefaults.standard.set(pwdString, forKey: CDUserDefaultKey.loginPassword)
//                UserDefaults.standard.synchronize()
                CDUtility.showMSG(message: "恭喜您，重置密码成功，重置后密码为6个0！")
                self.navigationController?.popViewController(animated: true)
                return
            }
            if let code = dict["Code"] as? Int,code == 1 {
                if let msgString = dict["Message"] as? String {
                    CDUtility.showMSG(message: msgString)
                }
            }
            
        }) {
            print("")
        }
        
    }
}
